package com.etocrm.saas.lib.base.common.result.uam.vo;

import com.etocrm.saas.lib.base.common.result.uam.enums.ResponseEnum;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;

import java.io.Serializable;

/**
 * UAM系统的统一结果集
 *
 * @Author chengrong.yang
 * @Date 2020/11/18 16:45
 */
@Data
@JsonInclude(JsonInclude.Include.NON_NULL)
public class ResponseVO<T> implements Serializable {

    private static final long serialVersionUID = 3530232874785067977L;
    /**
     * 异常码
     */
    private Integer code;

    /**
     * 描述
     */
    private String message;

    /**
     * 数据
     */
    private T data;

    public ResponseVO() {
    }

    public ResponseVO(Integer code, String msg) {
        this.code = code;
        this.message = msg;
    }

    public ResponseVO(Integer code, String msg, T data) {
        this.code = code;
        this.message = msg;
        this.data = data;
    }

    public ResponseVO(ResponseEnum responseEnum) {
        this.code = responseEnum.getCode();
        this.message = responseEnum.getMessage();
    }

    public ResponseVO(ResponseEnum responseEnum, T data) {
        this.code = responseEnum.getCode();
        this.message = responseEnum.getMessage();
        this.data = data;
    }

    public static ResponseVO<String> success() {
        return new ResponseVO<>(ResponseEnum.SUCCESS);
    }

    public static <T> ResponseVO<T> success(T data) {
        return new ResponseVO<>(ResponseEnum.SUCCESS, data);
    }

    public static <T> ResponseVO<T> success(int code, String msg) {
        return new ResponseVO<>(code, msg);
    }

    public static ResponseVO<String> error(int code, String msg) {
        return new ResponseVO<>(code, msg);
    }

    public static ResponseVO<String> error(ResponseEnum responseEnum) {
        return new ResponseVO<>(responseEnum);
    }

    public static <T> ResponseVO<T> error(ResponseEnum responseEnum, T data) {
        return new ResponseVO<>(responseEnum, data);
    }

    public static ResponseVO<String> errorParams(String msg) {
        return new ResponseVO<>(ResponseEnum.INCORRECT_PARAMS.getCode(), msg);
    }


}